-- UIStoneAlert
-- Created by chengb May/31/2015
-- 石柱警戒

UIStoneAlert = class("UIStoneAlert", function()
    return cc.Layer:create();
end);

function UIStoneAlert.create(stoneType)
    return UIStoneAlert.new(stoneType);
end

-- 构造函数
function UIStoneAlert:ctor(stoneType)
    self:setName("UIStoneAlert");
    local node = cc.CSLoader:createNode("layout/stone/StoneAlert.csb");
    self:addChild(node);
    self.node = node;

    self:setLocalZOrder(UIMgr.TOP_MENU_ZORDER + 2);

    assert(type(stoneType) == 'number', "必须传入石柱类型");

    -- 记录石柱类型
    self.stoneType = stoneType;

    -- 初始化窗口
    self:initForm();

    -- 适配
    self:resize();
end

-- 初始化窗口
function UIStoneAlert:initForm()
    local bg1 = findChildByName(self.node, "CT/bg1");
    local bg2 = findChildByName(self.node, "CT/bg2");
    local bg3 = findChildByName(self.node, "CT/bg3");
    local bg4 = findChildByName(self.node, "CT/bg4");

    local stoneType = self.stoneType;
    local icon;
    if stoneType == STONE_TYPE_LIGHT then
        -- 光系
        icon = "stone_alert2";
    else
        -- 暗系
        icon = "stone_alert1";
    end

    bg1:loadTexture("images/ui/stone/" .. icon .. ".png");
    bg2:loadTexture("images/ui/stone/" .. icon .. ".png");
    bg3:loadTexture("images/ui/stone/" .. icon .. ".png");
    bg4:loadTexture("images/ui/stone/" .. icon .. ".png");

    bg1:setOpacity(0);
    bg2:setOpacity(0);
    bg3:setOpacity(0);
    bg4:setOpacity(0);

    local duration = 1;

    bg1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
    bg2:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
    bg3:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
    bg4:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
end

-- 适配
function UIStoneAlert:resize()
    local node = self.node;
    local w = AlignM.frameSize.width;
    local h = AlignM.frameSize.height;
    node:setContentSize(w, h);

    local  ct = findChildByName(node, "CT");
    ct:setPosition(w/2, h/2);
    ct:setScaleX(w/DESIGN_WIDTH);
    ct:setScaleY(h/DESIGN_HEIGHT);
end



